import Request from '../common/js/request'

// 部门接口
class DepartmentService {
  /**
   * 根据部门名称查询部门是否存在
   * @param departmentName 部门名称
   * @param departmentId 部门Id
   */
  static getIsExistsByDepartmentName(departmentName, departmentId) {
    const url = '/api-upms/department/getIsExistsByDepartmentName'

    const data = {
      departmentName,
      departmentId
    }

    return Request.get(url, data)
  }

  /**
   * 根据部门名称查询部门列表
   * @param departmentName 部门名称
   */
  static getDepartmentsByDepartmentName(departmentName) {
    const url = '/api-upms/department/getDepartmentsByDepartmentName'

    const data = {
      departmentName
    }

    return Request.get(url, data)
  }

  /**
   * 添加部门
   * @param department 部门表单对象
   */
  static insertDepartment(department) {
    const url = '/api-upms/department/insertDepartment'

    const data = department

    return Request.post(url, data)
  }

  /**
   * 修改部门
   * @param department 部门表单对象
   */
  static updateDepartment(department) {
    const url = '/api-upms/department/updateDepartment'

    const data = department

    return Request.post(url, data)
  }

  /**
   * 删除部门
   * @param departmentIds 部门Id数组
   */
  static deleteDepartments(departmentIds) {
    const url = '/api-upms/department/deleteDepartments'

    const data = {
      departmentIds: departmentIds.toString()
    }

    return Request.post(url, data)
  }
}

export default DepartmentService
